home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / gcc < prev    next >
Encoding:
Text File  |  2010-11-16  |  1.6 KB  |  60 lines

  1. # gcc(1) completion
  2. #
  3. # The only unusual feature is that we don't parse "gcc --help -v" output
  4. # directly, because that would include the options of all the other backend
  5. # tools (linker, assembler, preprocessor, etc) without any indication that
  6. # you cannot feed such options to the gcc driver directly.  (For example, the
  7. # linker takes a -z option, but you must type -Wl,-z for gcc.)  Instead, we
  8. # ask the driver ("g++") for the name of the compiler ("cc1"), and parse the
  9. # --help output of the compiler.
  10.  
  11. have gcc &&
  12. _gcc()
  13. {
  14.     local cur cc backend
  15.  
  16.     COMPREPLY=()
  17.     _get_comp_words_by_ref cur
  18.  
  19.     _expand || return 0
  20.  
  21.     case $1 in
  22.         gcj)
  23.             backend=jc1
  24.             ;;
  25.         gpc)
  26.             backend=gpc1
  27.             ;;
  28.         *77)
  29.             backend=f771
  30.             ;;
  31.         *)
  32.             backend=cc1 # (near-)universal backend
  33.             ;;
  34.     esac
  35.  
  36.     if [[ "$cur" == -* ]]; then
  37.         cc=$( $1 -print-prog-name=$backend )
  38.         # sink stderr:
  39.         # for C/C++/ObjectiveC it's useless
  40.         # for FORTRAN/Java it's an error
  41.         COMPREPLY=( $( compgen -W "$( $cc --help 2>/dev/null | \
  42.            tr '\t' ' ' | \
  43.            sed -e '/^  *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
  44.            sort -u )" -- "$cur" ) )
  45.     else
  46.         _filedir
  47.     fi
  48. } &&
  49. complete -o filenames -F _gcc gcc g++ c++ g77 gcj gpc
  50. [ $USERLAND = GNU -o $UNAME = Cygwin ] && \
  51. [ -n "${have:-}" ] && complete -o filenames -F _gcc cc
  52.  
  53. # Local variables:
  54. # mode: shell-script
  55. # sh-basic-offset: 4
  56. # sh-indent-comment: t
  57. # indent-tabs-mode: nil
  58. # End:
  59. # ex: ts=4 sw=4 et filetype=sh
  60.